      SUBROUTINE PRINTR(NCOR,PLOTR,ERS,ERS1,ERD,RESCON,XY,NRES,CALC,
     1RESPRT)
      DOUBLE PRECISION SOS,SOS1,SIG,SIG1,MEAN,MEAN1,SIGL,SIGL1,ERS,ERS1,
     1 ERD, ENP, SOSL, SOS1L, E1, E2, V, X,ACC,YDPL
      COMMON /LONG/ ELONG(1)
      COMMON /LAT/ ELAT(1)
      COMMON /ALT/ EALT(1)
      COMMON/RESX/N,XPL(1)
      COMMON/RESY/YPL(1)
      COMMON/RESYD/YDPL(1)
      COMMON/RESF/FPL(1)
      COMMON /RESA/ ACC(1)
      COMMON /TEST/ ATABLE, LASTIT, RESSQ, DEBUG, SCPLOT, LASTPR, NCYCLE
      CHARACTER*4 IMAGE
      DIMENSION IMAGE(25),DX2(721)
      LOGICAL ATABLE, LASTIT, DEBUG, LASTPR,CALC,RESPRT
      LOGICAL RESET
      LOGICAL NOSET
      LOGICAL PLOTR,RESCON, SCPLOT
C      INTEGER LAB1(14),LAB2(14),LAB3(14),BOT(14),V1(10),V2(10),V3(10)
      DIMENSION XY(NRES,5)
C      DATA LAB1/84H   POSITION RESIDUALS
CC     1                               /
C      DATA LAB2/84H   VELOCITY RESIDUALS
C     1                               /
C      DATA LAB3/84H  ACCELERATION RESIDUALS * AND FORCES .
C     1                               /
C      DATA  BOT/84H          TIME
C     1                               /
C      DATA V1/60H
C     1     /
C      DATA V2/60H
C     1     /
C      DATA V3/60H
C     1     /
      DATA M /6/
C
C     INITIALIZATION
C
      SOSL=SOS
      SOS1L=SOS1
      ENP=DBLE(FLOAT(N))
      SOS=0.D0
      SOS1=0.D0
      MEAN=0.D0
      MEAN1=0.D0
      NMI=N-1
      DO 1 IDX=1,NMI
      DX2(IDX)=(XPL(IDX+1)-XPL(IDX))*12.0D0
    1 CONTINUE
      DX2(N)=(XPL(N)-XPL(N-1))*12.0D0
      GO TO (10, 80, 190), NCOR
C
C     PRINT POSITION RESIDUALS
C
   10 DO 20 I = 1, N
      MEAN = MEAN + YPL(I)
      SOS = SOS + YPL(I)**2
   20 CONTINUE
      SIG = DSQRT (SOS)/(ENP - 1.0D0)
      MEAN = MEAN/ENP
      IF (SIG .LT. ERS) PLOTR = .TRUE.
      IF(DABS(SIG-SIGL).LT.ERD)PLOTR=.TRUE.
      SIGL=SIG
      IF (.NOT. LASTPR) GO TO 320
      IF(.NOT. RESPRT) GO TO 65
      IPAGE = 0
      LINES = 56
      DO 60 I = 1, N
      IF (LINES .LT. 56) GO TO 40
      IPAGE = IPAGE + 1
      LINES = 5
      WRITE (M, 30) IPAGE
   30 FORMAT (18H1RESIDUALS - PAGE , I2/ 10H0LONGITUDE, 10X, 4HTIME, 6X,
     1 8HPOSITION/ 10H (DEGREES), 5X, 9H(MINUTES), 11X, 3H(M)/)
   40 WRITE (M, 50) ELONG(I), XPL(I), YPL(I)
   50 FORMAT (F10.2, F14.2, 4F14.5)
      LINES = LINES + 1
   60 CONTINUE
   65 CONTINUE
      WRITE (M, 70) SOS, SIG, MEAN
   70 FORMAT (8H0  SOS =, D15.8, 6X, 7HSIGMA =, D15.8, 6X, 7H MEAN =,
     1 D15.8)
      GO TO 320
C
C     PRINT VELOCITY RESIDUALS AND ACCELERATIONS
C
   80 DO 90 I = 1, N
      MEAN1=MEAN1+YDPL(I)
      SOS1=SOS1+YDPL(I)*YDPL(I)
   90 CONTINUE
      SIG1=DSQRT(SOS1)/(ENP-1.D0)
      MEAN1=MEAN1/ENP
      IF(SIG1.LT.ERS1)PLOTR=.TRUE.
      IF(DABS(SIG1-SIGL1).LT.ERD)PLOTR=.TRUE.
      SIGL1=SIG1
      IF (CALC) GO TO 130
      IF (.NOT. LASTPR) GO TO 320
      IF(.NOT. RESPRT) GO TO 125
      IPAGE = 0
      LINES = 56
      DO 120 I = 1, N
      IF (LINES .LT. 56) GO TO 110
      IPAGE = IPAGE + 1
      LINES = 5
      WRITE (M, 100) IPAGE
  100 FORMAT (18H1RESIDUALS - PAGE , I2/ 10H0LONGITUDE, 10X, 4HTIME, 6X,
     1 8HVELOCITY/ 10H (DEGREES), 5X, 9H(MINUTES), 6X, 8H(CM/SEC)/)
  110 WRITE (M, 50) ELONG(I), XPL(I), YDPL(I)
      LINES = LINES + 1
  120 CONTINUE
  125 CONTINUE
      WRITE (M, 70) SOS1, SIG1, MEAN1
      GO TO 320
  130 E1=0.D0
      E2=0.D0
      DO 140 I = 2, NMI
      ACC(I) = (YDPL(I+1) - YDPL(I-1))/DX2(I)
      X = ACC(I) - FPL(I)
      E1 = E1 +X
      E2 = E2 + X**2
  140 CONTINUE
      ACC(1) = (-3.0*YDPL(1) + 4.0*YDPL(2) - YDPL(3))/DX2(1)
      X = ACC(1) - FPL(1)
      E1 = E1 + X
      E2 = E2 + X**2
      ACC(N) = (3.0*YDPL(N) - 4.0*YDPL(N-1) + YDPL(N-2))/DX2(N)
      X = ACC(N) - FPL(N)
      E1 = (E1 + X)/ENP
      E2 = (E2 + X**2)/ENP
      V = E2 - E1**2
      IF (.NOT. LASTPR) GO TO 320
      IF(.NOT. RESPRT) GO TO 175
      IPAGE = 0
      LINES = 56
      DO 170 I = 1, N
      IF (LINES .LT. 56) GO TO 160
      IPAGE = IPAGE + 1
      LINES = 5
      WRITE (M, 150) IPAGE
  150 FORMAT (18H1RESIDUALS - PAGE , I2/ 10H0LONGITUDE, 10X, 4HTIME, 6X,
     1 8HVELOCITY, 2X, 12HACCELERATION, 9X, 5HFORCE/ 10H (DEGREES), 5X,
     2 9H(MINUTES), 6X, 8H(CM/SEC), 3X, 11H(MM/SEC**2), 3X,
     3 11H(MM/SEC**2)/)
  160 WRITE (M, 50) ELONG(I), XPL(I), YDPL(I), ACC(I), FPL(I)
      LINES = LINES + 1
  170 CONTINUE
  175 CONTINUE
      WRITE (M, 180) E1, E2, V
  180 FORMAT (8H0   E1 =, D15.8, 6X, 7H   E2 =, D15.8, 6X, 7H    V =,
     1 D15.8)
      WRITE (M, 70) SOS1, SIG1, MEAN1
      GO TO 320
C
C     PRINT POSITION RESIDUALS, VELOCITY RESIDUALS, AND ACCELERATIONS
C
  190 DO 200 I = 1, N
      MEAN=MEAN+YPL(I)
      SOS=SOS+YPL(I)*YPL(I)
      MEAN1=MEAN1+YDPL(I)
      SOS1=SOS1+YDPL(I)*YDPL(I)
  200 CONTINUE
      SIG=DSQRT(SOS)/(ENP-1.D0)
      SIG1=DSQRT(SOS1)/(ENP-1.D0)
      MEAN=MEAN/ENP
      MEAN1=MEAN1/ENP
      IF(SIG.LT.ERS.OR.SIG1.LT.ERS1)PLOTR=.TRUE.
      IF(DABS(SIG-SIGL).LT.ERD.OR.DABS(SIG1-SIGL1).LT.ERD)PLOTR=.TRUE.
      SIGL=SIG
      SIGL1=SIG1
      IF (CALC) GO TO 240
      IF (.NOT. LASTPR) GO TO 320
      IF(.NOT. RESPRT) GO TO 290
      IPAGE = 0
      LINES = 56
      DO 230 I = 1, N
      IF (LINES .LT. 56) GO TO 220
      IPAGE = IPAGE + 1
      LINES = 5
      WRITE (M, 210) IPAGE
  210 FORMAT (18H1RESIDUALS - PAGE , I2/ 10H0LONGITUDE, 10X, 4HTIME, 6X,
     1 8HPOSITION, 6X, 8HVELOCITY/ 10H (DEGREES), 5X, 9H(MINUTES), 11X,
     2 3H(M), 6X, 8H(CM/SEC)/)
  220 WRITE (M, 50) ELONG(I), XPL(I), YPL(I), YDPL(I)
      LINES = LINES + 1
  230 CONTINUE
      GO TO 290
  240 ACC(1) = (-3.0*YDPL(1) + 4.0*YDPL(2) - YDPL(3))/DX2(1)
      E1 = ACC(1) - FPL(1)
      E2 = E1**2
      DO 250 I = 2, NMI
      ACC(I) = (YDPL(I+1) - YDPL(I-1))/DX2(I)
      X = ACC(I) - FPL(I)
      E1 = E1 +X
      E2 = E2 + X**2
  250 CONTINUE
      ACC(N) = (3.0*YDPL(N) - 4.0*YDPL(N-1) + YDPL(N-2))/DX2(N)
      X = ACC(N) - FPL(N)
      E1 = (E1 + X)/ENP
      E2 = (E2 + X**2)/ENP
      V=E2-E1*E1
      IF (.NOT. LASTPR) GO TO 320
      IF(.NOT. RESPRT) GO TO 285
      IPAGE = 0
      LINES = 56
C
C     *********************************************************
C     THIS PRINT IS USED FOR POINT MASS MODEL
      DO 280 I = 1, N
C     CONVERT FORCE & ACCLERATION TO MGAL
C
      ACC(I) = ACC(I)*100.
      FPL(I)=FPL(I)*100.
C
      IF (LINES .LT. 56) GO TO 270
      IPAGE = IPAGE + 1
      LINES = 5
      WRITE (M, 260) IPAGE
  260 FORMAT (18H1RESIDUALS - PAGE , I2/ 7H0  TIME,6X,8HPOSITION,
     1 6X,5HFORCE,7X,12HACCELERATION,4X,8HLATITUDE,5X,
     2 9HLONGITUDE,3X,'ALTITUDE',/
     2        10H (MINUTES),5X,3H(M),9X,
     3 '(MGAL)',10X,'(MGAL)',6X,
     4 9H(DEGREES), 4X,9H(DEGREES),6X,'(KM)'/)
C
270   WRITE(M,51) XPL(I),YPL(I),FPL(I),ACC(I),ELAT(I),ELONG(I),EALT(I)
51    FORMAT(2X,F6.2,5X,F7.3,3X,F9.5,7X,F9.5,8X,F6.2,
     1 7X,F7.2,3X,F9.2)
      LINES = LINES + 1
  280 CONTINUE
  285 CONTINUE
      WRITE (M, 180) E1, E2, V
  290 WRITE (M, 300) SOS, SIG, MEAN
  300 FORMAT (8H0  SOS =, D15.8, 6X, 7HSIGMA =, D15.8, 6X, 7H MEAN =,
     1 D15.8, 6X, 9HPOSITIONS)
      WRITE (M, 310) SOS1, SIG1, MEAN1
  310 FORMAT (8H0  SOS =, D15.8, 6X, 7HSIGMA =, D15.8, 6X, 7H MEAN =,
     1 D15.8, 6X, 10HVELOCITIES)
  320 IF ((SOS .GT. SOSL .OR. SOS1 .GT. SOS1L) .AND. RESCON .AND.
     1 (SOSL + SOS1L) .GT. 1.0D-5) PLOTR = .TRUE.
      IF (.NOT. (PLOTR .AND. LASTPR)) GO TO 560
C
C     PLOT INITIALIZATION
C
      RESET = .TRUE.
      NOSET = .FALSE.
      FLN = 48.0
      NCHAR = FLN
      NCHAR=100
      DO 330 I = 1, N
      XY(I,1)=XPL(I)
      XY(I,2)=YPL(I)
      XY(I,3)=YDPL(I)
      XY(I,4)=ACC(I)
      XY(I,5)=FPL(I)
C     CHANGE ACCELERATION & FORCE BACK TO MM/S**2
      ACC(I) = ACC(I)/100.
      FPL(I) = FPL(I)/100.
  330 CONTINUE
      IF(NCOR.EQ.3) GO TO 480
      IF (NCOR .EQ. 2) GO TO 420
C
C     PRINTER PLOT OF POSITION RESIDUALS
C
      IPAGE = 0
      LINES = 56
      YLO = YMAX (YPL, N)
      CALL SCALES (YLO, YHI)
      YLO = -YHI
      BTM=100.
      TOP=-100.
      DO 400 I = 1, N
      BTM=AMIN1(BTM,YPL(I))
      TOP=AMAX1(TOP,YPL(I))
      CALL PRPL (YPL(I), 'P', IMAGE, NCHAR, YLO, YHI, RESET)
      IF (LINES - 54) 380, 340, 350
  340 CALL ENDSC
  350 IPAGE = IPAGE + 1
      LINES = 5
      WRITE (M, 360) IPAGE
  360 FORMAT (34H1PLOT OF POSITION RESIDUALS - PAGE, I3)
      CALL ENDSC
      WRITE (M, 370)
  370 FORMAT(4X,'LAT',5X,'LONG',4X,'TIME'/  8X,16H(DEGREES)  (MIN))
  380 WRITE (M, 390) ELAT(I), ELONG(I), XPL(I), IMAGE
  390 FORMAT (2X,F6.2,2X, 2F7.2,  8X, 25A4)
      LINES = LINES + 1
  400 CONTINUE
      CALL ENDSC
  410 IF(NCOR .EQ. 1) GO TO 560
C
C     PRINTER PLOT OF VELOCITY RESIDUALS
C
  420 IPAGE = 0
      LINES = 56
      YLO = YMAXD (YDPL, N)
      CALL SCALES (YLO, YHI)
      YLO = -YHI
      BTM=100.
      TOP=-100.
      DO 470 I = 1, N
      XNUBLE=YDPL(I)
      BTM=AMIN1(BTM,XNUBLE)
      TOP=AMAX1(TOP,XNUBLE)
      CALL PRPL (XNUBLE, 'V', IMAGE, NCHAR, YLO, YHI, RESET)
      IF (LINES - 54) 460, 430, 440
  430 CALL ENDSC
  440 IPAGE = IPAGE + 1
      LINES = 5
      WRITE (M, 450) IPAGE
  450 FORMAT (34H1PLOT OF VELOCITY RESIDUALS - PAGE, I3)
      CALL ENDSC
      WRITE (M, 370)
  460 WRITE (M, 390) ELAT(I), ELONG(I), XPL(I), IMAGE
      LINES = LINES + 1
  470 CONTINUE
      CALL ENDSC
C
C     PRINTER PLOT OF ACCELERATION RESIDUALS AND FORCES
C
  480 IPAGE = 0
      LINES = 56
      YTA = YMAXD (ACC, N)
      YTB = YMAX (FPL, N)
      YLO = AMAX1 (YTA, YTB)
      CALL SCALES (YLO, YHI)
      YLO = -YHI
      BTM=100.
      TOP=-100.
      WIDTH = YHI/FLN
      DO 550 I = 1, N
      BTM = AMIN1 (BTM, SNGL(ACC(I)), FPL(I))
      TOP = AMAX1 (TOP, SNGL(ACC(I)), FPL(I))
      MA = (ACC(I) + YHI)/WIDTH + 1.5
      XNUBLE=ACC(I)
      MB = (FPL(I) + YHI)/WIDTH + 1.5
      IF (MA .EQ. MB) GO TO 490
      CALL PRPL (XNUBLE, 'A', IMAGE, NCHAR, YLO, YHI, RESET)
      CALL PRPL (FPL(I), 'F', IMAGE, NCHAR, YLO, YHI, NOSET)
      GO TO 500
  490 CALL PRPL (XNUBLE, '*', IMAGE, NCHAR, YLO, YHI, RESET)
  500 IF (LINES - 54) 540, 510, 520
  510 CALL ENDSC
  520 IPAGE = IPAGE + 1
      LINES = 6
      WRITE (M, 530) IPAGE
  530 FORMAT (53H1PLOT OF ACCELERATION RESIDUALS (A) AND FORCES (F) - ,
     1 4HPAGE, I3/ 47H    (ASTERISKS (*) INDICATE OVERLAPPING POINTS))
      CALL ENDSC
      WRITE (M, 370)
  540 WRITE (M, 390) ELAT(I), ELONG(I), XPL(I), IMAGE
      LINES = LINES + 1
  550 CONTINUE
      CALL ENDSC
  560 RETURN
      END
